package cate.game.role.res.call;

import cate.common.table.call.row.CallWeightRow;
import cate.common.table.d.GDHeroCall;
import cate.common.table.item.hero.StarGroupList;
import cate.common.util.GameResult;
import cate.game.role.Role;
import cate.game.role.res.call.base.CallProcessData;
import cate.game.role.res.call.base.CallResult;
import cate.game.role.res.call.base.ICallHandler;
import cate.game.role.res.call.nature.CallNatureCallPO;

public class CallNatureBaseHandler implements ICallHandler<CallNatureCallPO> {

  private CallCommonBaseHandler handler = new CallCommonBaseHandler();

  @Override
  public boolean callPreCheck(Role role, CallProcessData processData, CallNatureCallPO basePO) {
    if (basePO.getSubMode(processData.base) == GDHeroCall.Mode.NATURE_SUB_BASE
            && basePO.times + processData.base.callTimes > GDHeroCall.NATURE_BASE_CALL_DAY_TIME_LIMIT) {
      role.getGame().notice.message(role, 310532, "当日许愿次数已到上限，明日再来吧！");
      return false;
    }
    return this.handler.callPreCheck(role, processData, basePO);
  }

  @Override
  public void singleCallExe(Role role, CallProcessData processData, CallNatureCallPO basePO) {
    if (basePO.getSubMode(processData.base) == GDHeroCall.Mode.NATURE_SUB_BASE) {
      processData.base.config.setup();
      StarGroupList.Item group = processData.base.config.get();
      if (group == null) {
        role.getGame().notice.message(role, "配置错误");
        return;
      }
      CallResult item = null;
      //普通模式
      CallWeightRow row = basePO.tool.doGeneralCallWithActivity(role, group.groupId);
      if (row == null) {
        return;
      }
      item = new CallResult(processData.consumedTimes + 1, row.id);

      processData.result.add(item);
    } else {
      this.handler.singleCallExe(role, processData, basePO);
    }
  }

  @Override
  public void singleCallAffect(Role role, CallProcessData processData, CallNatureCallPO basePO) {
    this.handler.singleCallAffect(role, processData, basePO);
  }

  @Override
  public void modifyByDifferentMod(Role role, CallProcessData processData, CallNatureCallPO basePO) {
    this.handler.modifyByDifferentMod(role, processData, basePO);
  }

  @Override
  public GameResult calcResult(Role role, CallProcessData processData, CallNatureCallPO basePO) {
    return this.handler.calcResult(role, processData, basePO);
  }
}
